package com.wu.client.controller;

import com.wu.client.service.CommunityService;
import com.wu.client.utils.MinIoUtil;
import com.wu.client.vo.req.post.PostAddReq;
import com.wu.client.vo.res.PageResp;
import com.wu.client.vo.res.community.PostResp;
import com.wu.common.convertion.result.Result;
import com.wu.common.convertion.result.Results;
import lombok.RequiredArgsConstructor;
import org.springframework.data.mongodb.core.aggregation.ArrayOperators;
import org.springframework.web.bind.annotation.*;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Base64;

/**
 * @author Cousin
 * @date 2025/4/6
 * @Description
 */
@RestController
@RequestMapping("community")
@RequiredArgsConstructor
public class communityController {
    private final CommunityService communityService;
    //http://localhost:8888/api/community/posts?page=1&limit=20
    @GetMapping("/posts")
    public Result<PageResp<PostResp>> getPosts(@RequestParam Integer page, @RequestParam Integer limit,
                                               @RequestParam Long userId, @RequestParam String type){

        return Results.success(communityService.getPosts(page,limit,userId,type));
    }
    @GetMapping("/profile/{userId}/posts")
    public Result<PageResp<PostResp>> getUserPosts(@PathVariable Long userId, @RequestParam(required = false) Long currentUserId
            , @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "5") Integer limit){
        return Results.success(communityService.getUserPosts(page,limit,currentUserId,userId));
    }
    //http://localhost:8888/api/locations/nearby
    @GetMapping("locations/nearby")
    public Object getNearbyLocation(){
        return "{\n" +
                "  \"success\": true,\n" +
                "  \"data\": {\n" +
                "    \"items\": [\n" +
                "      {\n" +
                "        \"name\": \"金迪世纪大厦\",\n" +
                "        \"address\": \"广东省深圳市南山区侨香路4018号\",\n" +
                "        \"distance\": 0,\n" +
                "        \"city\": \"深圳市\"\n" +
                "      },\n" +
                "      {\n" +
                "        \"name\": \"侨城北(地铁站)\",\n" +
                "        \"address\": \"广东省深圳市南山区2号线(8号线)\",\n" +
                "        \"distance\": 70.46,\n" +
                "        \"city\": \"深圳市\"\n" +
                "      },\n" +
                "      {\n" +
                "        \"name\": \"港龙舞蹈(华侨城校区)\",\n" +
                "        \"address\": \"广东省深圳市南山区侨香路天鹅湖花园三期华侨城欢乐时光3层06号\",\n" +
                "        \"distance\": 145.29,\n" +
                "        \"city\": \"深圳市\"\n" +
                "      },\n" +
                "      {\n" +
                "        \"name\": \"盒马鲜生(欢乐时光店)\",\n" +
                "        \"address\": \"广东省深圳市南山区侨香路天鹅湖花园三期OCT PARK华侨城欢乐时光B1层\",\n" +
                "        \"distance\": 145.45,\n" +
                "        \"city\": \"深圳市\"\n" +
                "      }\n" +
                "    ],\n" +
                "    \"total\": 4\n" +
                "  }\n" +
                "}\n";
    }
    //http://localhost:8888/api/community/posts
    @PostMapping("posts")
    public Result<Void> addPost(@RequestBody PostAddReq post) throws Exception {
            communityService.addPost(post);
        return Results.success();
        }
    @DeleteMapping("posts/{postId}")
    public Result<Void> deletePost(@PathVariable String postId) throws Exception {
        communityService.deletePost(postId);
        return Results.success();
    }
}
